module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 添加模块字段
    await queryInterface.addColumn('permissions', 'module', {
      type: Sequelize.STRING(100),
      allowNull: false,
      defaultValue: 'system',
      comment: '权限所属模块',
    });

    // 添加模块名称字段
    await queryInterface.addColumn('permissions', 'module_name', {
      type: Sequelize.STRING(100),
      allowNull: true,
      comment: '模块中文名称',
    });

    // 添加是否为系统权限字段
    await queryInterface.addColumn('permissions', 'is_system', {
      type: Sequelize.BOOLEAN,
      allowNull: false,
      defaultValue: false,
      comment: '是否为系统权限（系统权限不能分配给租户）',
    });

    // 添加排序字段
    await queryInterface.addColumn('permissions', 'sort_order', {
      type: Sequelize.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '排序序号',
    });

    // 添加索引
    await queryInterface.addIndex('permissions', ['module']);
  },

  down: async (queryInterface) => {
    await queryInterface.removeColumn('permissions', 'module');
    await queryInterface.removeColumn('permissions', 'module_name');
    await queryInterface.removeColumn('permissions', 'is_system');
    await queryInterface.removeColumn('permissions', 'sort_order');
  },
};

